/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import Bean.Err;
import exception.LoginException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.LoginManager;

/**
 *
 * @author Vincenzo
 */
public class Registrazione extends HttpServlet {
   
    private LoginManager lm;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        lm = (LoginManager) getServletContext().getAttribute("login-manager");
        Err e= new Err();
        String addr="";
        try{
        String username = request.getParameter("username");
        String password = request.getParameter("passworda");
        String work = request.getParameter("ruolo");
        String name = request.getParameter("nome");
        String surname = request.getParameter("cognome");
        String birthDate = request.getParameter("date3");
         lm.register(username, password, work, name, surname, birthDate);
            addr="/Jvinery/jsp/welcome.jsp";
        }

        catch (LoginException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            e.setError(ex.toString());
            addr="/Error.jsp";
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher(addr);
            dispatcher.forward(request, response);
    } 


    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       this.doGet(request, response);
    }

}
